import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router);

const router = new Router({
    mode: 'history',
        routes:[
            {
                path: '/',
                redirect: '/login',
            },
            {
                path:'/login',
                component:()=>import("../views/login")
            },{
                path:'/register',
                component:()=>import("../views/register")
            },
            {
                path:'/home',
                component: () =>import("../views/home"),
                children:[{
                    path:'/home/user/admin',
                    component:()=>import("../views/user/admin")
                },{
                    path:'/home/user/staff',
                    component:()=>import("../views/user/staff")
                },{
                    path:'/home/apartment/room',
                    component:()=>import("../views/room/room")
                },{
                    path:'/home/apartment/device',
                    component:()=>import("../views/device/device")
                },{
                    path:'/home/apartment/condition',
                    component:()=>import("../views/condition/condition")
                },
                    {
                        path:'/home/set/set',
                        component:()=>import("../views/set/set")
                    },
                ]
            }
        ]
    })

//路由导航守卫
// router.beforeEach((to,from,next)=>{
//     //如果前往登陆页面放行
//     if(to.path=='/'){
//         next()
//     }else{
//     //    取出客户端localStorage中存储的token
//         let token=localStorage.getItem('token')
//         //判断token是否存在，不存在则强制跳转到login界面 存在就放行
//         if(token===null||token===''){
//             console.log('请先登录')
//             next({path:'/'})
//         }else{
//             next()
//         }
//     }
// })
export default router
